home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / source / uFolderProps.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2005-01-26  |  12.5 KB  |  429 lines

  1. unit uFolderProps;
  2.  
  3. {
  4. *******************************************************************************
  5. * Descriptions: Implementation for Explorer properties click
  6. * $Source: /cvsroot/fma/fma/uFolderProps.pas,v $
  7. * $Locker:  $
  8. *
  9. * Todo:
  10. *      - use notebook in general page
  11. *
  12. * Change Log:
  13. * $Log: uFolderProps.pas,v $
  14. * Revision 1.11.6.1  2005/01/25 16:03:08  z_stoichev
  15. * Merged with 2.1 Beta 1 bugfixes
  16. *
  17. * Revision 1.11  2004/08/17 14:47:02  merijnb
  18. * added support for sub-dirs for preview
  19. *
  20. * Revision 1.10  2004/06/28 14:01:29  z_stoichev
  21. * Bugfixes and common General page.
  22. * Added bookmark editing support.
  23. *
  24. * Revision 1.9  2004/06/17 12:42:17  z_stoichev
  25. * Fixed Unicode
  26. *
  27. * Revision 1.8  2004/05/19 18:34:15  z_stoichev
  28. * Build 0.1.0.35c
  29. *
  30. * Revision 1.7  2004/03/26 18:37:39  z_stoichev
  31. * Build 0.1.0.35 RC5
  32. *
  33. * Revision 1.6  2004/03/08 12:54:22  z_stoichev
  34. * Phone number - msg/call contact
  35. * Autoupdate phone details every 1 sec
  36. *
  37. * Revision 1.5  2003/12/16 17:38:05  z_stoichev
  38. * Refresh gives error when folder does not exists.
  39. *
  40. * Revision 1.4  2003/12/11 14:55:24  z_stoichev
  41. * Fixed Explorer properties visual bug issues.
  42. * Phone properties now shown more phone information.
  43. *
  44. * Revision 1.3  2003/12/11 12:41:02  z_stoichev
  45. * Refresh obex file implemented.
  46. *
  47. * Revision 1.2  2003/11/28 09:38:07  z_stoichev
  48. * Merged with branch-release-1-1 (Fma 0.10.28c)
  49. *
  50. * Revision 1.1.2.4  2003/11/13 16:39:54  z_stoichev
  51. * Add more items type support.
  52. *
  53. *
  54. *
  55. }
  56.  
  57. interface
  58.  
  59. uses
  60.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  61.   Dialogs, StdCtrls, ComCtrls, ExtCtrls, TntComCtrls, TntStdCtrls,
  62.   GR32_Image, MPlayer, OKTThemeEngine;
  63.  
  64. const
  65.   fpNone = 0;
  66.   fpPhone = 1;
  67.   fpContact = 2;
  68.   fpBookmark = 3;
  69.   fpDB = 4;
  70.  
  71. type
  72.   TfrmFolderProps = class(TForm)
  73.     ApplyButton: TButton;
  74.     PageControl1: TPageControl;
  75.     TabSheet1: TTabSheet;
  76.     Image1: TImage;
  77.     TntEdit1: TTntEdit;
  78.     TabSheet3: TTabSheet;
  79.     PicPanel1: TPanel;
  80.     SelImage: TImage32;
  81.     MediaPlayer1: TMediaPlayer;
  82.     Label1: TLabel;
  83.     lblType: TLabel;
  84.     lblNoCache: TLabel;
  85.     btnDownload: TButton;
  86.     lblNote: TLabel;
  87.     Label3: TLabel;
  88.     Timer1: TTimer;
  89.     ThemeViewer1: TOKTThemeViewer;
  90.     ThemeContainer1: TOKTThemeContainer;
  91.     btnSS: TButton;
  92.     cbPreview: TComboBox;
  93.     SaveDialog1: TSaveDialog;
  94.     lblLocalFile: TLabel;
  95.     lblName: TTntLabel;
  96.     Button3: TButton;
  97.     NotebookPanel: TPanel;
  98.     Notebook1: TNotebook;
  99.     Label13: TLabel;
  100.     Label12: TLabel;
  101.     lbModel: TLabel;
  102.     lbManufacturer: TLabel;
  103.     Label14: TLabel;
  104.     Label16: TLabel;
  105.     lbSWRevision: TLabel;
  106.     lbSerialNumber: TLabel;
  107.     Label4: TLabel;
  108.     Label5: TLabel;
  109.     Label6: TLabel;
  110.     lbvbat: TLabel;
  111.     lbicharge: TLabel;
  112.     lbcyclescharge: TLabel;
  113.     Label7: TLabel;
  114.     lbdcio: TLabel;
  115.     lbiphone: TLabel;
  116.     Label8: TLabel;
  117.     Label9: TLabel;
  118.     lblTimeLeft: TLabel;
  119.     Label10: TLabel;
  120.     Label11: TLabel;
  121.     lbtempphone: TLabel;
  122.     lbtempbatt: TLabel;
  123.     lblContact: TTntLabel;
  124.     Button1: TButton;
  125.     Button2: TButton;
  126.     lblBookmark: TLabel;
  127.     edBookmark: TEdit;
  128.     Label2: TLabel;
  129.     Memo1: TMemo;
  130.     lblDB: TLabel;
  131.     Bevel1: TBevel;
  132.     procedure FormCreate(Sender: TObject);
  133.     procedure FormShow(Sender: TObject);
  134.     procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  135.       var DoDefault: Boolean);
  136.     procedure btnDownloadClick(Sender: TObject);
  137.     procedure Timer1Timer(Sender: TObject);
  138.     procedure cbPreviewChange(Sender: TObject);
  139.     procedure btnSSClick(Sender: TObject);
  140.   private
  141.     Filetype: integer;
  142.     Fullpath: string;
  143.     FRootNode: TtntTreeNode;
  144.     FBookmarkIndex: integer;
  145.     FBookmarkIndexPhone: integer;
  146.     procedure Set_RootNode(const Value: TtntTreeNode);
  147.     { Private declarations }
  148.     procedure UpdatePhoneDetails;
  149.     function Get_BmUrl: string;
  150.     function Get_BmTtl: WideString;
  151.   public
  152.     { Public declarations }
  153.     property RootNode: TtntTreeNode read FRootNode write Set_RootNode default nil;
  154.     //
  155.     property BookmarkPhoneIndex: integer read FBookmarkIndexPhone;
  156.     property BookmarkDataIndex: integer read FBookmarkIndex;
  157.     property BookmarkURL: string read Get_BmUrl;
  158.     property BookmarkTitle: WideString read Get_BmTtl;
  159.   end;
  160.  
  161. var
  162.   frmFolderProps: TfrmFolderProps;
  163.  
  164. implementation
  165.  
  166. uses Unit1, uGlobal;
  167.  
  168. {$R *.dfm}
  169.  
  170. procedure TfrmFolderProps.Set_RootNode(const Value: TtntTreeNode);
  171. var
  172.   id: Integer;
  173.   sl: TStringList;
  174.   i: integer;
  175. begin
  176.   Notebook1.PageIndex := fpNone;
  177.  
  178.   FRootNode := Value;
  179.   if Value = nil then begin
  180.     Memo1.Visible := False;
  181.     lblDB.Visible := False;
  182.     exit;
  183.   end;
  184.  
  185.   { Allow phone rename if connected and root is selected }
  186.   if Value = Form1.Explorer.Items[0] then begin
  187.     TntEdit1.Visible := True;
  188.     TntEdit1.Text := Value.Text;
  189.     { Get phone info }
  190.     UpdatePhoneDetails;
  191.     Notebook1.PageIndex := fpPhone;
  192.   end;
  193.  
  194.   if not Visible then begin // will be executed at least one (first time)
  195.     lblName.Caption := Value.Text;
  196.     Memo1.Lines.Clear;
  197.     Memo1.Visible := True;
  198.     lblDB.Visible := True;
  199.     id := Value.StateIndex;
  200.  
  201.     if Form1.PhoneIdentity <> '' then
  202.       Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\dat\'
  203.     else
  204.       Fullpath := ExePath;
  205.  
  206.     // Contacts
  207.     if (id and $F00000) = $100000 then begin
  208.       Memo1.Lines.Add(Fullpath+'Contacts.ME.dat');
  209.       Memo1.Lines.Add(Fullpath+'Contacts.SM.dat');
  210.       Memo1.Lines.Add(Fullpath+'Contacts.SYNC.dat');
  211.       Memo1.Lines.Add(Fullpath+'Contacts.SYNCMAX.dat');
  212.       Memo1.Lines.Add(Fullpath+'ContactSync.xml');
  213.     end;
  214.     // Messages
  215.     if (id and $F00000) = $200000 then begin
  216.       Memo1.Lines.Add(Fullpath+'SMSInbox.dat');
  217.       Memo1.Lines.Add(Fullpath+'SMSOutbox.dat');
  218.       Memo1.Lines.Add(Fullpath+'SMSSent.dat');
  219.       Memo1.Lines.Add(Fullpath+'SMSArchive.dat');
  220.     end;
  221.     // Organizer
  222.     if (id and $F00000) = $300000 then begin
  223.       Memo1.Lines.Add(Fullpath+'Bookmarks.dat');
  224.     end;
  225.     // Files, Profiles, Groups
  226.     if ((id and $F00000) = $500000) or ((id and $F00000) = $700000) or ((id and $F00000) = $800000) then begin
  227.        Memo1.Lines.Add('Dynamic Data');
  228.        Memo1.Lines.Add('(will be loaded from phone when connected)');
  229.     end;
  230.  
  231.     // Phones
  232.     if Value.ImageIndex in [9..13] then begin
  233.       lblContact.Caption := Value.Parent.Text;
  234.       Notebook1.PageIndex := fpContact;
  235.     end;
  236.  
  237.     edBookmark.Text := '';
  238.     if Value.ImageIndex = 59 then begin
  239.       sl := TStringList(Form1.FNodeBookmarks.Data);
  240.       i := 0;
  241.       while (i < sl.Count) do begin
  242.         if StrToInt(GetToken(sl[i],0)) = id then begin
  243.           FBookmarkIndex := i;
  244.           FBookmarkIndexPhone := id;
  245.           break;
  246.         end;
  247.         inc(i);
  248.       end;
  249.       if i < sl.Count then begin
  250.         edBookmark.Text := GetToken(sl[i],1);
  251.         TntEdit1.Visible := True;
  252.         TntEdit1.Text := Value.Text;
  253.         Notebook1.PageIndex := fpBookmark;
  254.       end;
  255.     end;
  256.  
  257.     if Memo1.Lines.Count <> 0 then begin
  258.       Notebook1.PageIndex := fpDB;
  259.     end;
  260.     NotebookPanel.Visible := Notebook1.PageIndex <> fpNone;
  261.   end;
  262.  
  263.   if TabSheet3.TabVisible then begin
  264.     Filetype := -1;
  265.     id := Form1.ExplorerFindExtImage(ExtractFileExt(Value.Text));
  266.     try
  267.       lblLocalFile.Caption := '';
  268.       case id of
  269.         36: // sound
  270.         begin
  271.           Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\snd\'+Value.Text;
  272.           if FileExists(Fullpath) then begin
  273.             lblNoCache.Caption := 'cached localy';
  274.             MediaPlayer1.FileName := Fullpath;
  275.             MediaPlayer1.Open;
  276.             MediaPlayer1.Enabled := True;
  277.             MediaPlayer1.Visible := True;
  278.             lblLocalFile.Caption := Fullpath;
  279.           end
  280.           else
  281.             lblNoCache.Caption := 'stored in phone';
  282.             btnDownload.Visible := True;
  283.             btnDownload.Enabled := True;
  284.             lblType.Caption := 'sound';
  285.             Filetype := 1;
  286.           end;
  287.         37: // image
  288.         begin
  289.           Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\pic\'+Value.Text;
  290.           if FileExists(Fullpath) then begin
  291.             lblNoCache.Caption := 'cached localy';
  292.             SelImage.Bitmap.LoadFromFile(Fullpath);
  293.             SelImage.Visible := True;
  294.             lblLocalFile.Caption := Fullpath;
  295.           end
  296.           else
  297.             lblNoCache.Caption := 'stored in phone';
  298.           btnDownload.Visible := True;
  299.           btnDownload.Enabled := True;
  300.           PicPanel1.Visible := True;
  301.           lblType.Caption := 'picture';
  302.           Filetype := 0;
  303.         end;
  304.         27: // theme
  305.         begin
  306.           Fullpath := ExePath+'data\'+Form1.PhoneIdentity+'\thm\'+Value.Text;
  307.           if FileExists(Fullpath) then begin
  308.             lblNoCache.Caption := 'cached localy';
  309.             ThemeContainer1.OpenTheme(Fullpath);
  310.             lblLocalFile.Caption := Fullpath;
  311.             ThemeViewer1.Preview := pvStandby;
  312.             ThemeViewer1.Visible := True;
  313.             cbPreview.ItemIndex := Ord(pvStandby)-1;
  314.             cbPreview.Visible := True;
  315.             btnSS.Visible := True;
  316.           end
  317.           else
  318.             lblNoCache.Caption := 'stored in phone';
  319.           btnDownload.Visible := True;
  320.           btnDownload.Enabled := True;
  321.           lblType.Caption := 'theme';
  322.           Filetype := 2;
  323.         end;
  324.       end;
  325.     except
  326.       lblNoCache.Caption := 'file damaged, or unknown format';
  327.       btnDownload.Visible := True;
  328.       btnDownload.Enabled := True;
  329.     end;
  330.     if not PicPanel1.Visible and not MediaPlayer1.Visible and (Filetype = -1) then begin
  331.       TabSheet3.TabVisible := False;
  332.     end;
  333.   end;  
  334. end;
  335.  
  336. procedure TfrmFolderProps.FormCreate(Sender: TObject);
  337. begin
  338. {$IFNDEF VER150}
  339.   Form1.ThemeManager1.CollectForms(Self);
  340. {$ENDIF}
  341. end;
  342.  
  343. procedure TfrmFolderProps.FormShow(Sender: TObject);
  344. begin
  345.   PageControl1.ActivePageIndex := 0;
  346. end;
  347.  
  348. procedure TfrmFolderProps.MediaPlayer1Click(Sender: TObject;
  349.   Button: TMPBtnType; var DoDefault: Boolean);
  350. begin
  351.   if Button = btStop then MediaPlayer1.Rewind;
  352. end;
  353.  
  354. procedure TfrmFolderProps.btnDownloadClick(Sender: TObject);
  355.  
  356.  function ExtractDir(Node: TTntTreeNode): string;
  357.  var ImageIndex: integer;
  358.  begin
  359.   Node := Node.Parent; // start at parent of 'file node'
  360.   Imageindex := Node.ImageIndex;
  361.  
  362.   while assigned(Node) and (Node.ImageIndex = ImageIndex) do
  363.   begin
  364.    result := Node.Text + '/' + result;
  365.    Node := Node.Parent;
  366.   end;
  367.  
  368.   if (Length(Result) > 1) and (Result[Length(Result)] = '/') then
  369.    SetLength(Result, Length(Result) - 1);
  370.  end;
  371.  
  372. begin
  373.   btnDownload.Enabled := False;
  374.   try
  375.     MediaPlayer1.Close;
  376.     ForceDirectories(ExtractFileDir(Fullpath));
  377.     Form1.ObexGetFile(Fullpath,{Form1.FindObexFolderName(Filetype)}ExtractDir(RootNode) +'/'+ExtractFileName(Fullpath));
  378.     RootNode := RootNode;  // force update of screen
  379.   finally
  380.     btnDownload.Enabled := True;
  381.   end;
  382. end;
  383.  
  384. procedure TfrmFolderProps.UpdatePhoneDetails;
  385. begin
  386.   lbManufacturer.Caption   := Form1.frmInfoView.lbManufacturer.Caption;
  387.   lbModel.Caption          := Form1.frmInfoView.lbModel.Caption;
  388.   lbSWRevision.Caption     := Form1.frmInfoView.lbSWRevision.Caption;
  389.   lbSerialNumber.Caption   := Form1.frmInfoView.lbSerialNumber.Caption;
  390.   lbvbat.Caption           := Form1.frmInfoView.lbvbat.Caption;
  391.   lbicharge.Caption        := Form1.frmInfoView.lbicharge.Caption;
  392.   lbcyclescharge.Caption   := Form1.frmInfoView.lbcyclescharge.Caption;
  393.   lbdcio.Caption           := Form1.frmInfoView.lbdcio.Caption;
  394.   lbiphone.Caption         := Form1.frmInfoView.lbiphone.Caption;
  395.   lblTimeLeft.Caption      := Form1.frmInfoView.lblTimeLeft.Caption;
  396.   lbtempbatt.Caption       := Form1.frmInfoView.lbtempbatt.Caption;
  397.   lbtempphone.Caption      := Form1.frmInfoView.lbtempphone.Caption;
  398.   Timer1.Enabled := True;
  399. end;
  400.  
  401. procedure TfrmFolderProps.Timer1Timer(Sender: TObject);
  402. begin
  403.   UpdatePhoneDetails;
  404. end;
  405.  
  406. procedure TfrmFolderProps.cbPreviewChange(Sender: TObject);
  407. begin
  408.   ThemeViewer1.Preview := TOKTPreview(cbPreview.ItemIndex+1);
  409. end;
  410.  
  411. procedure TfrmFolderProps.btnSSClick(Sender: TObject);
  412. begin
  413.   SaveDialog1.FileName := ChangeFileExt(lblName.Caption,'') + ' - ' + cbPreview.Text + '.bmp';
  414.   if SaveDialog1.Execute then
  415.     ThemeViewer1.ScreenShot.SaveToFile(SaveDialog1.FileName);
  416. end;
  417.  
  418. function TfrmFolderProps.Get_BmUrl: string;
  419. begin
  420.   Result := edBookmark.Text;
  421. end;
  422.  
  423. function TfrmFolderProps.Get_BmTtl: WideString;
  424. begin
  425.   Result := TntEdit1.Text;
  426. end;
  427.  
  428. end.
  429.